package com.lanou.zhihu.web.controller;

import com.lanou.zhihu.entity.User;
import com.lanou.zhihu.service.RemindService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by QuChao on 2018/11/1.
 */
@Controller
@RequestMapping("/remind")
public class RemindController {
    @Autowired
    private RemindService remindService;

    @ResponseBody
    @RequestMapping("/answerRemind")
    public Map<String, Object> answerRemind(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        User user = (User) request.getSession().getAttribute("user");
        List<Map<String, Object>> list = remindService.answerRemindByUid(user.getId());
        map.put("rows", list);
        return map;
    }

    @ResponseBody
    @RequestMapping("/commentRemind")
    public Map<String, Object> commentRemind(HttpServletRequest request) {
        Map<String, Object> map = new HashMap<>();
        User user = (User) request.getSession().getAttribute("user");
        List<Map<String, Object>> list = remindService.commentRemindByUid(user.getId());
        map.put("rows", list);
        return map;
    }

    @ResponseBody
    @RequestMapping("/readRemind")
    public boolean readRemindByAid(Integer aid) {
        return remindService.readRemindByAid(aid);
    }

    @ResponseBody
    @RequestMapping("/readCommentRemind")
    public boolean readCommentRemind(Integer cid) {
        return remindService.readCommentRemindByCid(cid);
    }
}
